home *** CD-ROM | disk | FTP | other *** search
- #ifdef HAS_SOCKET
- int
- do_socket(stab, arglast)
- STAB *stab;
- int *arglast;
- {
- register STR **st = stack->ary_array;
- register int sp = arglast[1];
- register STIO *stio;
- int domain, type, protocol, fd;
-
- if (!stab) {
- errno = EBADF;
- return FALSE;
- }
-
- stio = stab_io(stab);
- if (!stio)
- stio = stab_io(stab) = stio_new();
- else if (stio->ifp)
- do_close(stab,FALSE);
-
- domain = (int)str_gnum(st[++sp]);
- type = (int)str_gnum(st[++sp]);
- protocol = (int)str_gnum(st[++sp]);
- TAINT_PROPER("socket");
- fd = socket(domain,type,protocol);
- if (fd < 0)
- return FALSE;
- stio->ifp = fdopen(fd, "r"); /* stdio gets confused about sockets */
- stio->ofp = fdopen(fd, "w");
- stio->type = 's';
- if (!stio->ifp || !stio->ofp) {
- if (stio->ifp) fclose(stio->ifp);
- if (stio->ofp) fclose(stio->ofp);
- if (!stio->ifp && !stio->ofp) close(fd);
- return FALSE;
- }
-
- return TRUE;
- }
-
-